<?php

namespace app\admin\controller\api;

use app\model\RegionDao;
use think\admin\Controller;

class Region extends Controller
{
    public function index()
    {
        $data = $this->_vali([
            'parent_code.regex:^[0-9]{2,6}$' => '请选择地区'
        ]);
        $query=RegionDao::mQuery();
        if (!empty($data['parent_code'])) {
            $query->where('parent_code', $data['parent_code']);
        }else{
            $query->whereNull('parent_code');
        }
        $list=$query->order('sort asc')->select();
        $this->success('获取成功', $list);
    }

}